<?php

class CustomerController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    	
    	$mapper = new Application_Model_CustomerMapper();
    	
    	$entries = $mapper->getAll();
    	
    	$this->view->entries = $entries;
    	$this->pageTitle = 'List all customers';
        
    }
	
    public function editAction() 
    {
    	$request = $this->getRequest();
    	$form = new Application_Form_CustomerEdit();
    	$mapper = new Application_Model_CustomerMapper();
    		
    	if($request->isPost()) {
    		if ($form->isValid($request->getPost())) {
    			 
      			$mapper->changeMapping($form->getValues());
    				
    			$this->_redirect('customer/index');
    			$this->view->message = 'change has been done';
    		}
    	
    	} else {
    			
    		$param = $request->getParams(); //get ManagementUnit from URL
    	
    		if ($param['partyNumber'] == null)
    		{
    			die;
    		}
    		else {
    			$customer = $mapper->getCustomerById($param['partyNumber']); //get DataArray of Customer
    			
    			$form->populate($customer);	//fill form with mapping
    			
    		}
    	}
    	$this->view->pageTitle = 'Edit Customer';
    	
    	$this->view->form = $form;	//show form
    }

}

